package com.springboot.activemq.producter.demo.code;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;

@RestController
public class CreateMessageProducterController {

    private final JmsMessagingTemplate template;
    @Autowired
    public CreateMessageProducterController(JmsMessagingTemplate template) {
        this.template = template;
    }

    /**
     * 及时 消息
     * @return
     */
    @RequestMapping("/queue")
    public String queue(){
        // 构建一个消息, 名称是 queue01
        Destination destination = new ActiveMQQueue("queue01");
        String message = "我是消息内容, " + System.currentTimeMillis();
        template.convertAndSend(destination, message);
        return "success";
    }
}
